package com.geekbuy.net.native_dio_adapter;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

public class OkHttpClientManager {

  private OkHttpClient okHttpClient_;

  public static OkHttpClientManager sClientManager_ = new OkHttpClientManager();


  private OkHttpClientManager(){
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient.Builder builder = new OkHttpClient.Builder()
      .addInterceptor(loggingInterceptor)
      .retryOnConnectionFailure(false)
      .callTimeout(10000, TimeUnit.MILLISECONDS)
      .readTimeout(3000, TimeUnit.MILLISECONDS)//设置读取超时时间
      .writeTimeout(3000, TimeUnit.MILLISECONDS)//设置写的超时时间
      .connectTimeout(5000, TimeUnit.MILLISECONDS);//设置连接超时时间;

    okHttpClient_ = builder.build();
  }

  public static OkHttpClientManager getInstance(){
    return sClientManager_;
  }

  public OkHttpClient getOkHttpClient(){
    return okHttpClient_;
  }
}
